package com.cary.camerax.demo.utils;

import android.graphics.drawable.Drawable;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.cary.camerax.demo.CameraXApplication;

public class ResourceUtil {

    public static int getColor(int colorResId) {
        return ContextCompat.getColor(CameraXApplication.getInstance(), colorResId);
    }

    public static int getDimensionPixelSize(int dimenRes) {
        return CameraXApplication.getInstance().getResources().getDimensionPixelSize(dimenRes);
    }

    public static String getString(int strResId) {
        return CameraXApplication.getInstance().getString(strResId);
    }

    public static String getString(int strResId, Object... objects) {
        return String.format(getString(strResId), objects);
    }

    @Nullable
    public static Drawable getDrawable(int drawableResId) {
        if (drawableResId == 0) {
            return null;
        } else {
            return ContextCompat.getDrawable(CameraXApplication.getInstance(), drawableResId);
        }
    }
}
